package com.probox.modules.controller.platfom;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.PageDomain;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.core.web.page.TableSupport;
import com.probox.common.entity.domain.platfom.PlatformStoreTarget;
import com.probox.common.entity.mapper.system.SysUserMapper;
import com.probox.common.entity.service.platfom.IPlatformStoreTargetService;
import com.probox.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 门店目标业绩管理Controller
 *
 * @author usoft
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/system/target")
public class PlatformStoreTargetController extends BaseController {
    @Autowired
    private IPlatformStoreTargetService platformStoreTargetService;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询门店目标业绩管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PlatformStoreTarget platformStoreTarget) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<PlatformStoreTarget> list = platformStoreTargetService.getList(platformStoreTarget,pageNum,pageSize);
        return getDataTable(list);
    }


    /**
     * 导出门店目标业绩管理列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatformStoreTarget platformStoreTarget) throws IOException {
        List<PlatformStoreTarget> list = platformStoreTargetService.queryList(platformStoreTarget);
        ExcelUtil<PlatformStoreTarget> util = new ExcelUtil<PlatformStoreTarget>(PlatformStoreTarget.class);
        util.exportExcel(response, list, "门店目标业绩管理数据");
    }

    /**
     * 获取门店目标业绩管理详细信息
     */
    @GetMapping(value = "/{targetId}")
    public AjaxResult getInfo(@PathVariable("targetId") Long targetId) {
        return AjaxResult.success(platformStoreTargetService.selectPlatformStoreTargetById(targetId));
    }

    /**
     * 新增门店目标业绩管理
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PlatformStoreTarget platformStoreTarget) {
        return toAjax(platformStoreTargetService.insertPlatformStoreTarget(platformStoreTarget));
    }

    /**
     * 修改门店目标业绩管理
     */
    @PreAuthorize(hasPermi = "system:target:edit")
    @PutMapping("/updateTarget")
    public AjaxResult edit(@RequestBody PlatformStoreTarget platformStoreTarget) {
        return toAjax(platformStoreTargetService.updatePlatformStoreTarget(platformStoreTarget));
    }

    /**
     * 删除门店目标业绩管理
     */
    @DeleteMapping("/{targetIds}")
    public AjaxResult remove(@PathVariable Long[] targetIds) {
        return toAjax(platformStoreTargetService.deletePlatformStoreTargetByIds(targetIds));
    }
}
